package com.springboot.cloud.demos.ribbon.rest;

import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.demos.entity.form.AlbumForm;
import com.springboot.cloud.demos.entity.po.Album;
import com.springboot.cloud.demos.ribbon.service.AlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AlbumController {

    @Autowired
    private AlbumService albumService;


    @PostMapping("/album")
    public Result add(@RequestBody AlbumForm albumForm) {
        return albumService.save(albumForm);
    }

    @PutMapping(value = "/album")
    public Result save(@RequestBody Album album) {
        return albumService.update(album);
    }

    @RequestMapping(value = "/album/{id}", method = RequestMethod.GET)
    Result get(@PathVariable String id) {
        return albumService.get(id);
    }

    @RequestMapping(value = "/album/getAlbum", method = RequestMethod.GET)
    public Result<List<Album>> getAlbum(@RequestParam("momentId") String momentId) {
        return albumService.getAlbum(momentId);
    }

    @PostMapping(value = "/album/deleteByUrl")
    Result deleteByUrl(@RequestBody AlbumForm albumForm) {
        return albumService.deleteByUrl(albumForm);
    }

    @RequestMapping(value = "/album/{id}", method = RequestMethod.DELETE)
    Result delete(@PathVariable String id) {
        return albumService.delete(id);
    }

}
